package chapter12.casePage

/**
  * @Copyright: Shanghai Definesys Company.All rights reserved.
  * @Description:
  * @author: chuhaitao
  * @since: 2019/1/20 22:01
  * @history:
  *          1.2019/1/20 created by chuhaitao
  */
object PartialFunctionDemo {


  def main(args: Array[String]): Unit = {
    var list = List(1, 2, 3, "12", 12)


    var partialFunction = new PartialFunction[Any, Int] {
      //返回的是boolean类型
      override def isDefinedAt(x: Any): Boolean = x.isInstanceOf[Int]
      //如果isDefinedAt 返回的是正确的话，会调用下面的函数
      override def apply(v1: Any): Int = {
        v1.asInstanceOf[Int] + 1
      }
    }

    var list2 = list.collect(partialFunction)
    println(list2)
  }

}
